package dk.mirasola.systemtraining.info.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.Widget;
import dk.mirasola.systemtraining.info.client.i18n.InfoTexts;

public class InfoEntryPoint implements EntryPoint {
    interface InfoEntryPointUiBinder extends UiBinder<Widget,InfoEntryPoint> {}
    private static InfoEntryPointUiBinder uiBinder = GWT.create(InfoEntryPointUiBinder.class);
    private static InfoTexts texts = GWT.create(InfoTexts.class);


    @UiField
    Image dk;
    @UiField
    Image gb;
    @UiField
    HTML topHeader;
    @UiField
    HTML contentPanel;

    private static class LocaleClickHandler implements ClickHandler {
        private String locale;

        private LocaleClickHandler(String locale) {
            this.locale = locale;
        }

        @Override
        public void onClick(ClickEvent clickEvent) {
            Window.Location.assign(Window.Location.createUrlBuilder().setParameter("locale", locale).buildString());
        }
    }

    @Override
    public void onModuleLoad() {
        RootLayoutPanel.get().add(uiBinder.createAndBindUi(this));
        topHeader.setHTML(texts.topHeader());
        contentPanel.setHTML(texts.infoContent());
        dk.addClickHandler(new LocaleClickHandler("da"));
        gb.addClickHandler(new LocaleClickHandler("en"));
    }
}
